package io.github.mcsdk.ui.data;

import java.util.ArrayList;
import java.util.List;

/**
 * Simple implementation of IDataProvider
 *
 * @param <T> The type of data items
 * @author MC SDK Team
 * @version 1.0.0
 * @since 1.0.0
 */
public class ListDataProvider<T> implements IDataProvider<T> {

    private List<T> data;

    public ListDataProvider() {
        this.data = new ArrayList<>();
    }

    public ListDataProvider(List<T> initialData) {
        this.data = new ArrayList<>(initialData);
    }

    @Override
    public List<T> getData() {
        return data;
    }

    @Override
    public void setData(List<T> data) {
        this.data = new ArrayList<>(data);
    }

    @Override
    public T getItem(int index) {
        return data.get(index);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}